//
//  ScrollViewVC_2.m
//  UILbrary
//
//  Created by Apple on 2022/5/8.
//  Copyright © 2022 mac. All rights reserved.
//

#import "ScrollViewVC_2.h"
#import "MYHeader.h"

@interface ScrollViewVC_2 ()

@end

@implementation ScrollViewVC_2

- (void)viewDidLoad {
    [super viewDidLoad];
    self.view.backgroundColor = [UIColor whiteColor];
    [self p_scrollViewDemo];
}

- (void)p_scrollViewDemo
{
    UIScrollView *scrollView = [UIScrollView new];
    scrollView.bounces = NO;
    [self.view addSubview:scrollView];

    [scrollView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.mas_equalTo(self.view.mas_topMargin).offset(220);
        make.left.mas_equalTo(self.view).offset(10);
        make.right.mas_equalTo(self.view).offset(-10);
        // 这个高度是临时的，后面会改 成 contentView 的高度
        make.height.mas_equalTo(200);
    }];
    
    
    UIView *contentView = [[UIView alloc] init];
    contentView.backgroundColor = [UIColor whiteColor];
    [scrollView addSubview:contentView];
    
    [self.view layoutIfNeeded];
    [scrollView layoutIfNeeded];
    CGRect scrollView_frame = scrollView.frame;
    CGFloat contentView_width = scrollView_frame.size.width - 10;

    [contentView mas_makeConstraints:^(MASConstraintMaker *make) {
            make.top.equalTo(scrollView).inset(15.f);
            make.left.equalTo(scrollView).inset(15.f);
            make.right.equalTo(scrollView).inset(-15.f);
            make.bottom.equalTo(scrollView).inset(-15.f);
            make.width.mas_equalTo(contentView_width);
            make.height.greaterThanOrEqualTo(@0);
    }];

    for (NSInteger i = 0; i<10; i++) {
        UIView *view = [UIView new];
        view.backgroundColor = [UIColor grayColor];
        [contentView addSubview:view];
    }
    
    NSInteger warpCount = 3;
    CGFloat ItemWidth = 80;
    CGFloat marge = 20;
    CGFloat fixedInteritemSpacing = (SCREEN_WIDTH - warpCount * ItemWidth - marge * 2) / (warpCount - 1);
    CGFloat fixedItemHeight = 40;
    CGFloat fixedLineSpacing = 10;
    [contentView.subviews mas_distributeSudokuViewsWithFixedItemWidth:ItemWidth fixedItemHeight:fixedItemHeight fixedLineSpacing:fixedLineSpacing fixedInteritemSpacing:fixedInteritemSpacing warpCount:warpCount topSpacing:marge bottomSpacing:marge leadSpacing:marge tailSpacing:marge];
    
    [contentView layoutIfNeeded];
    CGFloat scrollView_height = contentView.frame.size.height;
    [scrollView mas_updateConstraints:^(MASConstraintMaker *make) {
        make.height.mas_equalTo(scrollView_height);
    }];
}



@end
